﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Level26EnglishLetters2 : MonoBehaviour
{
    public List<TextButton> textButtonList = new List<TextButton>();
    private string finalStr;
    public GameLevelItem gameLevelItem;
    void Start()
    {
        InitTextButton();
    }

    private void InitTextButton()
    {
        int length = textButtonList.Count;
        for (int i = 0; i < length; i++)
        {
            int index = i;
            textButtonList[i].Init(GetDefautLetter(index), () =>
            {
                TextButtonClick(index);
            });
        }
    }

    private void TextButtonClick(int index)
    {
        if (GameCtrl.Instance.curGameState == GameState.Play)
        {
            TextButton tb = textButtonList[index];
            tb.text.text = GetNextLetter(tb.text.text);
            Judge();
        }
    }

    private void Judge()
    {
        int length = textButtonList.Count;
        finalStr = string.Empty;
        for (int i = 0; i < length; i++)
        {
            finalStr += textButtonList[i].text.text;
        }
        if (finalStr.Equals(UConst.Str_TargetLove))
            gameLevelItem.TriggerResult(true);

    }


    public string GetNextLetter(string letter)
    {
        string nextLetter = string.Empty;
        switch (letter)
        {
            case "a":
                nextLetter = "b";
                break;
            case "b":
                nextLetter = "c";
                break;
            case "c":
                nextLetter = "d";
                break;
            case "d":
                nextLetter = "e";
                break;
            case "e":
                nextLetter = "f";
                break;
            case "f":
                nextLetter = "g";
                break;
            case "g":
                nextLetter = "h";
                break;
            case "h":
                nextLetter = "i";
                break;
            case "i":
                nextLetter = "j";
                break;
            case "j":
                nextLetter = "k";
                break;
            case "k":
                nextLetter = "l";
                break;
            case "l":
                nextLetter = "m";
                break;
            case "m":
                nextLetter = "n";
                break;
            case "n":
                nextLetter = "o";
                break;
            case "o":
                nextLetter = "p";
                break;
            case "p":
                nextLetter = "q";
                break;
            case "q":
                nextLetter = "r";
                break;
            case "r":
                nextLetter = "s";
                break;
            case "s":
                nextLetter = "t";
                break;
            case "t":
                nextLetter = "u";
                break;
            case "u":
                nextLetter = "v";
                break;
            case "v":
                nextLetter = "w";
                break;
            case "w":
                nextLetter = "x";
                break;
            case "x":
                nextLetter = "y";
                break;
            case "y":
                nextLetter = "z";
                break;
            case "z":
                nextLetter = "a";
                break;
            default:
                break;
        }
        return nextLetter;
    }

    public string GetDefautLetter(int index)
    {
        string letter = string.Empty;
        switch (index)
        {
            case 0:
                letter = "n";
                break;
            case 1:
                letter = "i";
                break;
            case 2:
                letter = "g";
                break;
            case 3:
                letter = "h";
                break;
            case 4:
                letter = "t";
                break;
            default:
                break;


        }
        return letter;
    }
}
